// CMeshPropertiesDlg.cpp : implementation file
//

#include "stdafx.h"
#include "TerrainEditor.h"
#include "MeshPropertiesDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMeshPropertiesDlg dialog


CMeshPropertiesDlg::CMeshPropertiesDlg(CWnd* pParent, CTerrainEditorDoc *pDoc)
:CDialog(CMeshPropertiesDlg::IDD, pParent)
{
	m_pDoc = pDoc;

	//{{AFX_DATA_INIT(CMeshPropertiesDlg)
	//}}AFX_DATA_INIT
}


void CMeshPropertiesDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMeshPropertiesDlg)
	DDX_Control(pDX, IDC_BUTTON_EditMeshApply, m_Apply);
	DDX_Control(pDX, IDC_EDIT_MaxMeshHeight, m_MaxMeshHeight);
	DDX_Control(pDX, IDC_EDIT_MeshSpacing, m_MeshSpacing);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CMeshPropertiesDlg, CDialog)
	//{{AFX_MSG_MAP(CMeshPropertiesDlg)
	ON_BN_CLICKED(IDC_BUTTON_EditMeshApply, OnButtonEditMeshApply)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMeshPropertiesDlg message handlers

BOOL CMeshPropertiesDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	CString str;
	
	str.Format(_T("%.0f"), m_pDoc->m_TerrainMesh.m_fMaxHeight);
	m_MaxMeshHeight.SetWindowText(str);
	str.Format(_T("%.0f"), m_pDoc->m_TerrainMesh.m_fMeshSpacing);
	m_MeshSpacing.SetWindowText(str);

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CMeshPropertiesDlg::OnButtonEditMeshApply() 
{
	UpdateData();

	float fMaxMeshHeight = m_MaxMeshHeight.ReturnFloat();
	float fMeshSpacing = m_MeshSpacing.ReturnFloat();
	
	// Error check

	if (fMaxMeshHeight < 1 || fMeshSpacing < 1) return;

	// Make changes

	m_pDoc->m_TerrainMesh.AdjustMesh(fMaxMeshHeight, fMeshSpacing);

	// Update the view

	m_pDoc->UpdateAllViews(NULL);
}

